<!DOCTYPE html>
<html>
<head>
<script src=resources/common.js></script>
<script src=../resources/testharness.js></script>
<script src=../resources/testharnessreport.js></script>

<script>
const priority_tests = [
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?1', location), document),
    expected_priority: kHigh,
    description: 'high importance on <script> has no effect'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?2', location), document),
    expected_priority: kLow,
    description: 'low importance on <script> lowers priority to kLow'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?3', location), document),
    expected_priority: kHigh,
    description: 'auto importance on <script> has no effect'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?4', location), document),
    expected_priority: kHigh,
    description: 'invalid importance on <script> has no effect'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?5', location), document),
    expected_priority: kHigh,
    description: 'missing importance on <script> has no effect'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?6', location), document),
    expected_priority: kHigh,
    description: 'high importance on late-body <script> raises priority to kHigh'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?7', location), document),
    expected_priority: kLow,
    description: 'low importance on late-body <script> lowers priority to kLow'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?8', location), document),
    expected_priority: kMedium,
    description: 'auto importance on late-body <script> has no effect (kMedium)'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?9', location), document),
    expected_priority: kMedium,
    description: 'invalid importance on late-body <script> has no effect (kMedium)'
  },
  {
    promise: internals.getInitialResourcePriority(new URL('../resources/dummy.js?10', location), document),
    expected_priority: kMedium,
    description: 'missing importance on late-body <script> has no effect (kMedium)'
  }
];

</script>

<script id=script1 importance=high src=../resources/dummy.js?1></script>
<script id=script2 importance=low src=../resources/dummy.js?2></script>
<script id=script3 importance=auto src=../resources/dummy.js?3></script>
<script id=script4 importance=xyz src=../resources/dummy.js?4></script>
<script id=script5 src=../resources/dummy.js?5></script>

<script>
  promise_test(async (t) => {
    await new Promise(resolve => {
      addEventListener('DOMContentLoaded', resolve);
    });

    const base_msg = ' was fetched by the preload scanner';
    assert_true(internals.isPreloaded(script1.src), script1.src + base_msg);
    assert_true(internals.isPreloaded(script2.src), script2.src + base_msg);
    assert_true(internals.isPreloaded(script3.src), script3.src + base_msg);
    assert_true(internals.isPreloaded(script4.src), script4.src + base_msg);
    assert_true(internals.isPreloaded(script5.src), script5.src + base_msg);
  }, 'all scripts were fetched by the preload scanner');

  // Setup the tests described by |priority_tests|.
  for (const test of priority_tests) {
    promise_test(async () => {
      const priority = await test.promise;
      assert_equals(priority, test.expected_priority);
    }, test.description);
  }
</script>
</head>
<body>
<!-- Dummy Image to delineate late-body -->
<img src="../resources/square.png">

<script id=script6 importance=high src=../resources/dummy.js?6></script>
<script id=script7 importance=low src=../resources/dummy.js?7></script>
<script id=script8 importance=auto src=../resources/dummy.js?8></script>
<script id=script9 importance=xyz src=../resources/dummy.js?9></script>
<script id=script10 src=../resources/dummy.js?10></script>

</body>
</html>